//
//  WBHomeTitleButton.swift
//  WeiBoApp
//
//  Created by CrazyHacker on 16/7/4.
//  Copyright © 2016年 CrazyHacker. All rights reserved.
//

import UIKit

class WBHomeTitleButton: UIButton {

        init(title: String?) {
        super.init(frame: CGRect())
            if title == nil {
                setTitle("首页" + "", for: [])
            } else {
                setTitle(title, for: [])
                setImage(UIImage(named: "navigationbar_arrow_down"), for: [])
                setImage(UIImage(named: "navigationbar_arrow_up"), for: .selected)
            }
                titleLabel?.font = UIFont.systemFont(ofSize: 17)
                setTitleColor(UIColor.darkGray(), for: [])
                // 设置大小
                sizeToFit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        guard let titleLabel = titleLabel, imageView = imageView else {
            return
        }
        
        titleLabel.frame = titleLabel.frame.offsetBy(dx: -imageView.bounds.width, dy: 0)
        imageView.frame = imageView.frame.offsetBy(dx: titleLabel.bounds.width + 8, dy: 0)
    
    }
}
